import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
	state:{
		imgUrl: 'http://module.zanboon.com:8086/',
		URL: "http://module.zanboon.com:8086/",
		H5URL: "http://module.zanboon.com:8086/",
		
		avatarUrl: '',
		nickName: '',
		token: '',
		isAuthorization: false,
		userId: '',
	},
	getters:{
		getUrl(state){
			return state.URL;
		},
		getToken(state){
			if(state.token) {
				return state.token;
			}else {
				console.log('getToken---',uni.getStorageSync('token'));
				return uni.getStorageSync('token');
			}
		},
		getUserId:function(state) {
			if(state.userId!='') {
				return state.userId
			}else {
				return uni.getStorageSync('userId');
			}
		}
	},
	mutations:{
		updataToken(state,token){
			uni.setStorage({
				key: 'token',
				data: token,
				success: function () {
				}
			});
			state.token = token;
			state.isAuthorization = true;
			console.log("updataToken")
		},
		updataUserId(state,userId){
			state.userId = userId;
		},
		updataUserInfo(state,info){
			if (info.account_id) {
				state.account_id = account_id
			}
			uni.setStorage({
				key: 'nickName',
				data: info.nickName,
				success: function () {
				}
			});
			uni.setStorage({
				key: 'avatarUrl',
				data: info.avatarUrl,
				success: function () {
				}
			});
			state.nickName = info.nickName;
			state.avatarUrl = info.avatarUrl;
		}
		
	}
})

export default store